package com.silverbox.shopper.dubboApi.order;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.silverbox.core.annotation.DataSource;
import com.silverbox.core.exception.CoreException;
import com.silverbox.core.exception.CoreException.CoreExceptionCode;
import com.silverbox.core.util.StringUtils;
import com.silverbox.shopper.entity.CupboardOrderRecord;
import com.silverbox.shopper.entity.RelMachineHardWare;
import com.silverbox.shopper.service.order.OrderService;

@Service
@DataSource(name = DataSource.DATASOURCE_A)
public class OrderServiceApiImpl implements OrderServiceApi {

	@Autowired
	private OrderService orderService;

	@Override
	public Integer updateAndGetOrderSeq(Integer storeId, Integer orderType) {
		if (storeId == null) {
			throw new CoreException("storeId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (orderType == null) {
			throw new CoreException("orderType is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		return orderService.updateAndGetOrderSeq(storeId, orderType);
	}

	@Override
	public List<CupboardOrderRecord> getOnlineMealRecordByNum(CupboardOrderRecord orderRecord) {
		if(orderRecord==null){
			throw new CoreException("orderRecord is null 查询柜子信息异常", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		return orderService.getOnlineMealRecordByNum(orderRecord);
	}

	@Override
	public RelMachineHardWare getMachineHardWareInfo(RelMachineHardWare machineHard) {
		return orderService.getMachineHardWareInfo(machineHard);
	}

	@Override
	public int saveCupboardOrderRecord(CupboardOrderRecord orderRecord) {
		if(orderRecord==null){
			throw new CoreException("orderRecord is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if(StringUtils.isEmpty(orderRecord.getOrderNum())){
			throw new CoreException("orderNum is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		return orderService.saveCupboardOrderRecord(orderRecord);
	}

	@Override
	public List<CupboardOrderRecord> getCupboardGoodsStatus(String orderNum, Long itemId,Date createTime) {
		if(StringUtils.isEmpty(orderNum)){
			throw new CoreException("orderNum is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if(itemId==null){
			throw new CoreException("itemId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		return orderService.getCupboardGoodsStatus(orderNum,itemId,createTime);
	}

	@Override
	public boolean isOpenInvoice(Integer storeId, String orderNum) {
		if(StringUtils.isEmpty(orderNum)){
			throw new CoreException("orderNum is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if(storeId==null){
			throw new CoreException("storeId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		return orderService.isOpenInvoice(storeId, orderNum);
	}

}
